package com.wiscamp.ninechapters.problems.domain.models.problems.problems.composite;

import com.wiscamp.ninechapters.common.core.CollectionHelper;
import com.wiscamp.ninechapters.problems.domain.models.problems.problems.CompositeProblem;
import com.wiscamp.ninechapters.problems.domain.models.problems.questions.ColumnCalculationQuestion;
import com.wiscamp.ninechapters.problems.domain.models.problems.questions.Question;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 单题型复合题-列式计算
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class CompositeColumnCalculationProblem extends CompositeProblem {
    /**
     * 单结果计算问题列表
     */
    private Collection<ColumnCalculationQuestion> questions = new ArrayList<>();

    @Override
    public void setCurrentQuestions(Collection<Question> questions) {
        this.questions.clear();
        for (var question : questions) {
            addQuestion(question);
        }
    }

    @Override
    public Collection<Question> getCurrentQuestions() {
        return CollectionHelper.convertToArrayList(questions);
    }

    @Override
    public void addQuestion(Question question) {
        if (!(question instanceof ColumnCalculationQuestion)) {
            throw new ClassCastException("无效的Question类型转换。");
        }
        this.questions.add((ColumnCalculationQuestion) question);
    }
}
